<?PHP
include_once "ini.php";
$tag = $_GET['tag'];
$json = array ();
$i = 0;
dbconnect();
$query = "SELECT * FROM indexation WHERE keyword = '".$tag."';";
$result = mysql_query($query);
if (!$result)
{
    echo "SQL error : ", $query;
    exit ;
}
else
{
    $tab = mysql_fetch_assoc($result);
    if ($tab['keyword'] != "")
    {
        $id_mot = $tab['id_mot'];

        $sql = "SELECT * FROM tags WHERE id_mot = '".$id_mot."';";
        $requete = mysql_query($sql);
        if (!$requete)
        {
            echo "SQL error : ", $sql;
            exit ;
        }
        else
        {
            while ($tableau = mysql_fetch_assoc($requete))
            {
                $sql2 = "SELECT * FROM users WHERE id_user = '".$tableau['id_user']."';";
                $requete2 = mysql_query($sql2);
                if (!$requete2)
                {
                    echo "SQL error : ", $sql2;
                    exit ;
                }
                else
                {
                	while($tabl = mysql_fetch_assoc($requete2)){
                    $json[$i] = array ("id_mot"=>$tabl['id_user'], "id_user"=>$tableau['id_user'], "login"=>$tabl['nom_user'], "latitude"=>$tabl['latitude'], "longitude"=>$tabl['longitude'], "altitude"=>$tabl['altitude'], "tag_occurence"=>$tableau['tag_occurence']);
                    $i++;
					}
                }
            }

        }
    }
   
echo json_encode($json);
}
dbclose();
?>
